package util{
	
	import flash.events.MouseEvent;
	
	import model.siw.SIW;
	
	import mx.containers.TitleWindow;
	import mx.controls.Button;
	import mx.controls.Label;
	import mx.controls.TextArea;
	import mx.controls.TextInput;
	import mx.events.CloseEvent;
	import mx.managers.PopUpManager;
	
	public class CreateSIW extends TitleWindow{
		
		private var siwPrompt:Label;
		
		private var text:TextInput;
		
		private var prompt:Label;
		
		private var okBtn:Button;
		
		private var cancelBtn:Button;
		
		public function CreateSIW(label:Label){
			
			this.siwPrompt=label;
			
			this.width = 270;
            this.height = 120;
            this.showCloseButton=true;
            this.addEventListener(CloseEvent.CLOSE, onClose);
            
            this.layout="absolute";
            
            prompt=new Label();
            prompt.text="名称:";
            prompt.x=10;
            prompt.y=10;
            prompt.width=60;
            prompt.height=24;
            
            text=new TextInput();
			text.x=85;
			text.y=10;
			text.width=130;
			text.height=24;
			
			okBtn=new Button();			
			okBtn.x=prompt.x;
			okBtn.y=prompt.y+prompt.height+10;
			okBtn.width=80;
			okBtn.height=20;
			okBtn.label="确认";
			
			cancelBtn=new Button();			
			cancelBtn.x=text.x+text.width-80;
			cancelBtn.y=text.y+text.height+10;
			cancelBtn.width=80;
			cancelBtn.height=20;
			cancelBtn.label="取消";
			
			okBtn.addEventListener(MouseEvent.CLICK, onFinish);
			cancelBtn.addEventListener(MouseEvent.CLICK, onCancel);
			this.addChild(prompt);
			this.addChild(text);
			this.addChild(okBtn);
			this.addChild(cancelBtn);
            
		}
		
		private function onClose(e:CloseEvent){
			PopUpManager.removePopUp(this);
		}
		
		private function onFinish(e:MouseEvent){
			if(text.text!=""){
				var siw:SIW=SIW.createInstance();
				siw.name=text.text;
				siw.id=Utils.genUUID();
				siwPrompt.text="交互窗口:"+siw.name+"("+siw.id+")";
				
			}else{
				return;
			}
			PopUpManager.removePopUp(this);
		}
		
		private function onCancel(e:MouseEvent){
			PopUpManager.removePopUp(this);
		}

	}
}